import { wyyxHttp } from '@/utils/request.ts'
import type { IDefaultKeyword } from '@/types/search.d.ts'
import type { GoodList, ReqGoodListParams } from '@/types/search.d.ts'

/**
 * @description 搜索框输入实时获取关联词
 * @param keyword 输入的关键词
 */
export const reqInputKeyword = (keyword: string) => {
  return wyyxHttp<string[]>('/xhr/search/searchAutoComplete.json?csrf_token=93361ea49b3c6fe00a6838a38e7b0047', 'POST',
    { keywordPrefix: keyword })
}

/**
 * @description 获取默认关键词和热门关键词
 */
export const reqTagInfo = () => {
  return wyyxHttp<IDefaultKeyword>('/xhr/search/init.json?csrf_token=93361ea49b3c6fe00a6838a38e7b0047', 'POST')
}

/**
 * @description 获取商品列表
 * @param csrf_token
 * @param __timestamp
 * @param keyword
 * @param sortType
 * @param descSorted
 * @param categoryId
 * @param matchType
 * @param floorPrice
 * @param upperPrice
 * @param size
 * @param itemId
 * @param stillSearch
 * @param searchWordSource
 * @param needPopWindow
 * @param _stat_search
 */
export const reqGoodList = ({
                              csrf_token,
                              __timestamp,
                              keyword,
                              sortType,
                              descSorted,
                              categoryId,
                              matchType,
                              floorPrice,
                              upperPrice,
                              size,
                              itemId,
                              stillSearch,
                              searchWordSource,
                              needPopWindow,
                              _stat_search
                            }: ReqGoodListParams) => {
  return wyyxHttp<GoodList>(`/xhr/search/search.json
      ?csrf_token=${csrf_token}
      &__timestamp=${__timestamp}
      &keyword=${keyword}
      &sortType=${sortType}
      &descSorted=${descSorted}
      &categoryId=${categoryId}
      &matchType=${matchType}
      &floorPrice=${floorPrice}
      &upperPrice=${upperPrice}
      &size=${size}
      &itemId=${itemId}
      &stillSearch=${stillSearch}
      &searchWordSource=${searchWordSource}
      &needPopWindow=${needPopWindow}
      &_stat_search=${_stat_search}`,
    'GET')
}
